/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.blue.input;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author kelvio
 */
public class InputDeviceManager {
    
    private Map<String, InputDevice> inputDeviceMap = new HashMap<>();
    
    private static class InputDeviceManagerHolder {
        private static final InputDeviceManager INSTANCE = new InputDeviceManager();
    }
    
    private InputDeviceManager() {}
    
    public InputDeviceManager getInstance() {
        return InputDeviceManagerHolder.INSTANCE;
    }
    
    public <T extends InputDevice> T getInputDevice(Class<? extends InputDevice> inputDeviceClass) {
        if (!inputDeviceMap.containsKey(inputDeviceClass.getName())) {
            throw new InputDeviceNotFoundException("The input device " + inputDeviceClass.getName() + " cannot be found.");
        }
        return (T) this.inputDeviceMap.get(inputDeviceClass.getName());
    }
    
    
    /**
     * 
     * @param inputDeviceClass
     * @param instance 
     */
    public void registerInputDevice(Class<? extends InputDevice> inputDeviceClass, InputDevice instance) {
       this.inputDeviceMap.put(inputDeviceClass.getName(), instance); 
    }

}
